<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="../style/journal.css" type="text/css" />
<style type="text/css"><!--
.googleadsense {
	margin: 2px;
	padding: 0px;
//--></style><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-65008-1";
urchinTracker();
</script><title>XML-PRC Client 客户端编写</title>
</head>
<body>
<a href="index.html">Journal</a>(2005) | <a href="../blog/"><b>Blog</b></a>(2006) | <a href="http://www.fayland.org/cgi-bin/random_link.pl">RandomLink</a> | <a href="AboutFayland.html">WhoAmI</a> | <a href="LiveBookmark.html">LiveBookmark</a> | <a href="http://www.fayland.org/">HomePage</a>
<p><&lt;Previous: <a href="050301.html">Goodbye, CET 6</a>&nbsp;&nbsp;>>Next: <a href="Apocalypse_005.html">Apocalypse RFC 005</a></p>
<h1>XML-PRC Client 客户端编写</h1>
<div class='content'>
<p>Category: <a href='Modules.html'>Modules</a> &nbsp; Keywords: <b>XML PRC</b></p>暑假里看了些XML的书，<a href='http://fund.perlchina.org'>fund.perlchina</a> 又出了个 xml-rpc 接口，便想着用 perl 做个客户端试试。<br>
客户端完成后，过几天试着用这几个模块做个服务端/Server.<p>

<h2>xml-rpc Server 结构介绍</h2>
因为 hoowa 在忙着编写 fund.perl 的 xml-rpc 的第二版, 而当我连接 <a href='http://fund.perlchina.org/archive/poda.php'>http://fund.perlchina.org/archive/poda.php</a> 并调用 archive.index 时总返回“404 Not Found”。想着当 hoowa 完成时再写连接 fund.perl 的代码。<p>

在 <a href='http://www.xml-rpc.com'>http://www.xml-rpc.com</a> 找了个 XML-RPC interface. 地址为：<a href='http://xmlrpc.scripting.com/discuss/msgReader$2014'>http://xmlrpc.scripting.com/discuss/msgReader$2014</a><p>

是 Weblogs.Com 的 XML-RPC 接口。大致的结构如下：
<pre>url: http://rpc.weblogs.com/RPC2
method: weblogUpdates.ping (weblogname, weblogurl, changesurl=weblogurl, categoryname="none") returns struct</pre>
我们的例子为调用 weblogUpdates.ping, 'Scripting News', 'http://www.scripting.com/'<br>
返回值取其中的 message = 'Thanks for the ping.' or 'Thanks for the ping, however we can only accept one ping every half-hour.'

<h2>Frontier::RPC</h2>
<pre><code>
use Frontier::Client;

my $url = 'http://rpc.weblogs.com/RPC2';

my $client = Frontier::Client->new(
 &nbsp; &nbsp;url => $url,
 &nbsp; &nbsp;debug => 1,
);
# Call the remote server and get our result.
my $result = $client->call('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/');

print $result->{'message'};
</code></pre>
Refrence:<br>
<a href='http://www-900.ibm.com/developerWorks/cn/webservices/ws-xpc1/index.shtml'>http://www-900.ibm.com/developerWorks/cn/webservices/ws-xpc1/index.shtml</a> （中文）<br>
<a href='http://search.cpan.org/perldoc?Frontier::Client'>perldoc Frontier::Client</a>

<h2>XML::RPC</h2>
<pre><code>
my $cli = RPC::XML::Client->new('http://rpc.weblogs.com/RPC2');

my $request = RPC::XML::request->new('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/');

my $response = $cli->simple_request($request);

if (!$response) {
    print "$RPC::XML::ERROR \n"; # No response
}
else {
    print $response->{'message'};
}
</code></pre>
Refrence:<br>
<a href='http://www.perlmonks.org/index.pl?node_id=340799'>http://www.perlmonks.org/index.pl?node_id=340799</a><br>
<a href='http://search.cpan.org/dist/RPC-XML/lib/RPC/XML.pm'>http://search.cpan.org/dist/RPC-XML/lib/RPC/XML.pm</a>

<h2>XMLRPC::Lite</h2>
<pre><code>
use XMLRPC::Lite;

my $result =  XMLRPC::Lite
      -> proxy('http://rpc.weblogs.com/RPC2')
      -> call('weblogUpdates.ping', 'Scripting News', 'http://www.scripting.com/')
      -> result;

print $result->{'message'};
</code></pre>
Refrence:<br>
<a href='http://search.cpan.org/perldoc?XMLPRC::Lite'>perldoc XMLPRC::Lite</a>

<h2>Further References</h2>
<ul>
<li><a href='http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html'>http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html</a>
<li><a href='http://www.infocopter.com/perl/xml-rpc-samples.htm'>XML RPC Samples</a>
<li><a href='http://www.blackperl.com/RPC::XML/'>http://www.blackperl.com/RPC::XML/</a>
<li><a href='http://www.xmlrpc.com/spec/'>XML-RPC Specification</a>
</ul>

<h2>Add @ 2005/3/3</h2>
问了问 hoowa fund.perlchina 的 xml-rpc 接口，他给了我一段样例。原来是地址错了，挂不得总是回 404 Not Found.
<pre>
use XMLRPC::Lite;

my $rpc = 'http://fund.perlchina.org/archive/poa.php';

my $client=XMLRPC::Lite->new();
$client->proxy($rpc);
my $archive= $client->call('archive.getindex'=>{order=>'1',limit=>'11'})->result;

foreach (@{$archive}) {
 &nbsp; &nbsp;my %result = %{$_};
 &nbsp; &nbsp;print $result{'title'}, "\n";
}
</pre></div>
<p><&lt;Previous: <a href="050301.html">Goodbye, CET 6</a>&nbsp;&nbsp;>>Next: <a href="Apocalypse_005.html">Apocalypse RFC 005</a></p>
<p><strong>Options:</strong> <a href='http://del.icio.us/post?title=XML-PRC%20Client%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BC%96%E5%86%99&url=http://www.fayland.org/journal/xml-rpc-client.html'>+Del.icio.us</a></p>
<strong>Related items</strong>
<ul><li><a href='perlxmlqstart1.html'>快速开始Perl XML：接口篇</a> < <span class='digit'>2004-12-27 22:17:54</span> ></li><li><a href='RSS.html'>给网页增加RSS</a> < <span class='digit'>2005-01-12 18:22:53</span> ></li><li><a href='Catalyst_XMLRPC.html'>Catalyst && XML-RPC</a> < <span class='digit'>2005-10-11 21:50:30</span> ></li></ul>
Created on <span class="digit">2005-03-02 00:04:31</span>, Last modified on <span class="digit">2005-05-21 00:13:19</span><br />
Copyright 2004-2005 All Rights Reserved. Powered by <a href="Eplanet.html">Eplanet</a> && <a href='http://catalyst.perl.org'>Catalyst</a> 5.62.
</body>
</html>